<?php

 // +----------------------------------------------------------------------
// | ADM Software [ 我宁可 为做过的事而后悔，也不想 因为没尝试而后悔。 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 扬州安蝶梦电子商务有限公司 All rights reserved.
// +----------------------------------------------------------------------
// | Author: 曹梦龙 <138888611@qq.com> <http://www.andiemeng.com>
// +----------------------------------------------------------------------
namespace Org\Util;
/**
 * Description of AEQuery
 *
 * @author Myron
 */
class AEQuery {
    private $_databasename;
    private $_classname;
    private $_dataArray = array();
    public  $objectId; 
    private $AeHttp;

     /*
     * 构造函数
     */
    function __construct($databasename='',$tablename = '') { //初始化对象，将初始化值放在括号内
        $this->_databasename=$databasename;
        $this->_classname = $tablename;
        $this->AeHttp = new \Org\Util\AEHttp($databasename);
    }
    
    /**
     * 通过ID 获取一个对象
     * @param type $objectId
     */
    function get($objectId=""){
        $this->objectId=$objectId;
        $result= $this->AeHttp->get($this->_classname, $objectId); 
        $body_rwa=(array)$result->data; 
        $aeobj=new AEObject($this->_databasename,$this->_classname); 
        return $aeobj->_QuerySet($body_rwa);
    }
    
    /**
     * 通过where条件返回对象数组
     */
    public function find($where,$limit=100,$skip=0,$sort='id-'){ 
         $result= $this->AeHttp->find($this->_classname, $where,$limit,$skip,$sort); 
         $AeObjArray ;
         for($i=0;$i<count($result->data);$i++){
            $aeobj=new AEObject($this->_databasename,$this->_classname); 
            $aeobj->_QuerySet((array)$result->data[$i]);
            $AeObjArray[$i]=$aeobj;
         }
         return $AeObjArray;
    }
    
    /**
     * 根据查询条件统计返回数量
     */
    public function count($where){
         $result= $this->AeHttp->count($this->_classname, $where);
         return $result->data;
    }
}
